﻿using es.typescript;
using Jurassic;
using System;
using System.IO;
using System.Threading.Tasks;

namespace NTypeScript.Demo
{
    public class person
    {
        public string name;

        public person(string name)
        {
            this.name = name;
        }

        public void fuckSomeone(string who)
        {
            Console.WriteLine($"I'm {name},now I going to fuck {who}");
        }
    }

    internal class Program
    {
        private static void Main(string[] args)
        {
            //testRunts().Wait();
            testRunFile("nnp5test.ts").Wait();
            echo("程序结束，按任意键退出");
            Console.ReadKey(true);
        }



        private static async Task testRunFile(string filepath)
        {
            TSEngine engine = new TSEngine();

            echo("初始化ts编译器");
            await engine.Init();

            //注册对象
            engine.EnableNNP5();        //启用nnp5
            engine.EnableConsole();     //启用控制台输出

            //JIT编译
            CompiledScript script = await engine.Compile(File.ReadAllText(filepath));

            //运行
            await engine.Execute(script);
        }





        private static async Task testRunts()
        {
            TSEngine engine = new TSEngine();

            echo("初始化ts编译器");
            await engine.Init();

            //注册对象
            engine.SetObject("birdman", new person("鸟人"));
            engine.EnableConsole();     //启用控制台输出


            string ts = @"
class fucker {
    test() {
        console.log(""good good study!day day fuck!"");
    }
}
let t = new fucker();
t.test();

birdman.fuckSomeone('山猪');
";

            //JIT编译
            CompiledScript script = await engine.Compile(ts);

            //运行
            await engine.Execute(script);
        }




        static void echo(string msg) => Console.WriteLine(msg);
    }
}